<?php

/*
 * @copyright :     Ienter asia Technologies
 * @author :        Quyet
 * @version         v.1.0
 * @created         01/7/2014
 * @Description :   Controller leave type
 */
if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Mod_leavetypes extends MYAD_Controller {

    function __construct() {
        parent::__construct();
        $this->load->model('Mmod_leavetypes', 'lt');
    }

    function index($page = 0) {
        $data = $this->lt->getAllData($page);
        $this->load->view('layout', $data);
    }

    function updateLeaveType() {
        /* check exists */
        $leaveTypeId = $this->input->post('txtLeaveTypeId');
        $leaveType = TRUE;
        if ($leaveTypeId) {
            $leaveType = $this->lt->countLeaveTypeByID($leaveTypeId);
        }
        if (!$leaveType) {
            redirect('/leave-types');
        }
        $temp = array();
        if (isset($_POST['btnSubmit'])) {
            $validateFlag = $this->lt->validate();
            if ($validateFlag) {
                /* validate success */
                $temp = $this->lt->updateLeaveType($leaveTypeId);
            }
        }
        $data = $this->lt->getAddLeaveType($leaveTypeId);
        $this->load->view('layout', array_merge($data, $temp));
    }

}

?>